package com.ghosthigh.simpleaccount.guice;

import com.ghosthigh.simpleaccount.server.url.UrlModule;
import com.ghosthigh.simpleaccount.server.url.Urls;
import com.ghosthigh.simpleaccount.servlet.HtmlServlet;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.servlet.GuiceServletContextListener;
import com.google.inject.servlet.ServletModule;

/**
 * Guice initializer.
 *
 * @author Jaesun Park
 */
public class GuiceServletConfig extends GuiceServletContextListener{

  private final class StaticServletModule extends ServletModule {
    @Override
    protected void configureServlets() {
      Urls urls = new Urls();
      serve(
          urls.getRoot(),
          urls.getStaticRoot(),
          urls.getStaticPattern()).with(HtmlServlet.class);
    }
  }

  @Override
  protected Injector getInjector() {
    Injector injector = Guice.createInjector(
        new StaticServletModule(),
        new UrlModule());
    return injector;
  }

}
